package com.lineage.data.item_etcitem.furniture;

import com.lineage.data.executor.ItemExecutor;
import com.lineage.server.datatables.lock.FurnitureSpawnReading;
import com.lineage.server.model.Instance.L1FurnitureInstance;
import com.lineage.server.model.Instance.L1ItemInstance;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.model.L1HouseLocation;
import com.lineage.server.model.L1Object;
import com.lineage.server.serverpackets.S_ServerMessage;
import com.lineage.server.serverpackets.ServerBasePacket;
import com.lineage.server.utils.L1SpawnUtil;
import com.lineage.server.world.World;
import java.util.Iterator;

public class BlackTiger extends ItemExecutor {
  public static ItemExecutor get() {
    return new BlackTiger();
  }
  
  public void execute(int[] data, L1PcInstance pc, L1ItemInstance item) {
    int itemObjectId = item.getId();
    if (!L1HouseLocation.isInHouse(pc.getX(), pc.getY(), pc.getMapId())) {
      pc.sendPackets((ServerBasePacket)new S_ServerMessage(563));
      return;
    } 
    boolean isAppear = true;
    L1FurnitureInstance furniture = null;
    Iterator<L1Object> iterator = World.get().getObject().iterator();
    while (iterator.hasNext()) {
      L1Object l1object = iterator.next();
      if (l1object instanceof L1FurnitureInstance) {
        furniture = (L1FurnitureInstance)l1object;
        if (furniture.getItemObjId() == itemObjectId) {
          isAppear = false;
          break;
        } 
      } 
    } 
    if (pc.getHeading() != 0 && pc.getHeading() != 2) {
      pc.sendPackets((ServerBasePacket)new S_ServerMessage(79));
      return;
    } 
    int npcId = 80114;
    if (isAppear) {
      L1SpawnUtil.spawn(pc, 80114, itemObjectId);
    } else {
      furniture.deleteMe();
      FurnitureSpawnReading.get().deleteFurniture(furniture);
    } 
  }
}
